package com.taotao.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.taotao.common.EasyUITree;
import com.taotao.mapper.TbItemCatMapper;
import com.taotao.pojo.TbItemCat;
import com.taotao.pojo.TbItemCatExample;
import com.taotao.pojo.TbItemCatExample.Criteria;
import com.taotao.service.ItemCatService;

@Service
public class ItemCatServiceImpl implements ItemCatService {
	
	@Autowired
	private TbItemCatMapper itemCatMapper;

	@Override
	public List<EasyUITree> getItemCategoryList(long parentId) {
		
		TbItemCatExample example = new TbItemCatExample();
		Criteria criteria = example.createCriteria();
		criteria.andParentIdEqualTo(parentId);
	
		List<TbItemCat> list = itemCatMapper.selectByExample(example);
		List<EasyUITree> easyUITrees = new ArrayList<>();
		for (TbItemCat tbItemCat : list) {
			EasyUITree easyUITree = new EasyUITree();
			easyUITree.setId(tbItemCat.getId());
			easyUITree.setText(tbItemCat.getName());
			easyUITree.setState(tbItemCat.getIsParent()?"closed":"open");
			easyUITrees.add(easyUITree);
		}
		
		return easyUITrees;
	}

}
